package com.zggk.framework.utils.gist;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;

/**
 * 
  * 处理Gis分页
  * @author 杜天[dutian] Email:13594731440@163.com Tel:17600471932
  * @date 2018年5月10日 下午2:28:23
 */
public class PageGisUtils {

	/**
	 * 
	  * @Description 封装Gis分页的Pageable
	  * @author 杜天[dutian] Email:13594731440@163.com Tel:17600471932
	  * @param request
	  * @return
	  * @throws Exception
	 */
	public static Pageable dealGisRequest(HttpServletRequest request) throws Exception{
		int currentPage = Integer.parseInt(request.getParameter("currentPage"));//获取当前页
		int pageSize = Integer.parseInt(request.getParameter("pageSize"));//需要查询的个数
		Direction direction = Sort.Direction.ASC;
		String sortField = request.getParameter("sortField");//排序字段
		Sort s  =null;
		if(StringUtils.isNotBlank(sortField)) {
			 s=new Sort(direction,sortField.split(","));
		}
		
		
		Pageable pageable = new PageRequest(currentPage-1, pageSize, s);
		return pageable;
		
	}
}
